<template>
	<view>
		<uni-forms style="margin-left: 2.5%; margin-right: 2.5%; margin-top: 5%;" ref="form" v-model="activity">
			<uni-forms-item label="活动名称" required>
				<uni-easyinput v-model="activity.name"/>
			</uni-forms-item>
			
			<uni-forms-item label="类型" required>
				<uni-data-picker placeholder="请选择类型" popupTitle="请选择发布活动的类别" :localdata="type" v-model="activity.type"/>
			</uni-forms-item>
			
			<uni-forms-item label="活动阶段" required>
				<uni-easyinput v-model="activity.stageNames" placeholder="活动阶段请用中文逗号分隔"/>
			</uni-forms-item>
			
		</uni-forms>
		
		
	</view>
	<view>
		<button type="primary" @click="submit">下一步</button>
	</view>
	<view>
	<uni-popup ref="alertDialog" type="dialog">
		<uni-popup-dialog :type="msgType" cancelText="关闭" confirmText="确认" title="提示信息" :content="messageText"></uni-popup-dialog>
	</uni-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				activity:{hostUid:0,
				name:"", 
				beginTime:"", 
				endTime:"", 
				place:"", 
				type:"", 
				state:"checking", 
				info:"", 
				addedTimes:0,
				stageNames:"",
				stageCount:0,
				content:"",
				pic1:'',
				pic2:'',
				pic3:'',
				},
				token:"",
				activityId:0,
				type:[
					{value:"文体",text:"文体"},
					{value:"学术",text:"学术"},
					{value:'社交',text:"社交"},
					{value:"竞赛",text:"竞赛"}
				],
				pics:[],
				messageText:"",
				msgType:"success"
			}
		},
		onLoad(){
			this.activity.hostUid= uni.getStorageSync("uid");
			this.token = uni.getStorageSync("token")
    		},
		methods: {
			choosepic(){
				uni.chooseImage({
					count: 3, 
					sourceType: ['album'], 
					success:(res)=> {
						this.pics = res.tempFilePaths;
					}
				})
			},
			messageToggle(msg) {
				this.msgType = this.msgType
				this.messageText = msg
				this.$refs.alertDialog.open()
			},
			submit(){
				//先测试要提交的信息如何
				let verify = true;
				let msg = "";
				this.msgType = "success"
				
				if(this.activity.name == ""){
					verify = false;
					msg = "活动名不能为空"
				}
				
				
				if(verify){
					if(this.activity.type == ""){
						verify = false;
						msg = "活动类型不能为空"
					}
				}
				
				
				
				if(verify){
					if(this.activity.stageNames == ""){
						verify = false;
						msg = "活动阶段不能为空";
					}
					this.activity.stageNames = this.activity.stageNames.replaceAll(',','，');
					this.stageCount =  this.activity.stageNames.split("，").length;
					console.log(this.stageCount);
				}
				
				
				if(verify){
					uni.setStorageSync("activity",this.activity);
					uni.navigateTo({
						url:"/pages/putActivity/putActivity2",
					})
				}
				else{
					this.msgType = "error";
					this.messageToggle(msg);
				}
			},
		}
	}
</script>


<style>

</style>
